package com.gongpingjialoan.view;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;

import com.gongpingjialoan.R;
import com.gongpingjialoan.activity.main.LoginActivity;
import com.gongpingjialoan.activity.main.MainActivity;
import com.gongpingjialoan.utility.DhUtil;
import com.gongpingjialoan.utility.SharedPreferencesUtil;

/**
 * Created by Administrator on 2016/1/25.
 */
public class CarListDialog  extends Dialog  implements View.OnClickListener{

    private int padding;

    private MainActivity mActivity;

    private Button sureButton , cancaleButton;

    public CarListDialog(Context context) {
        super(context, R.style.dialogs);
        mActivity = (MainActivity) context;
        padding = DhUtil.dip2px(context, 20);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.car_list_dialog);
        Window win = getWindow();
        win.getDecorView().setPadding(padding, 0, padding, 0);
        WindowManager.LayoutParams lp = win.getAttributes();
        lp.width = WindowManager.LayoutParams.MATCH_PARENT;
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        win.setAttributes(lp);
        setCanceledOnTouchOutside(false);
        setCancelable(false);

        sureButton = (Button) findViewById(R.id.sure);
        cancaleButton = (Button) findViewById(R.id.cancle);
        sureButton.setOnClickListener(this);
        cancaleButton.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        if(v == cancaleButton){
            dismiss();
        }else if(v == sureButton){
            Intent intent = new Intent(mActivity, LoginActivity.class);
            mActivity.startActivityForResult(intent , 0xda23);
            SharedPreferencesUtil.put(getContext() , "isShowCheshiNotification" , true);
            dismiss();
        }

    }
}
